1. /* sdfasinb.cpp by K.Tsuru May 22 2015 */
  2. // this is a reference function since ver. 2.21
  3. /***********************************************************************
  4. SDouble class with binary splitting.
  5. It provides arcsin(x) using Newton's method i.e. by solving the equation
  6. f(x) = sin(x) - a = 0 (x = arcsin(a)).
  7. It does iteration
  8. x1 = x0 + delta
  9. where delta = (a - sin(x0))/ cos(x0)
  10. sin(x0) and cos(x0) can be obtained at the same time by CosSinBS(x0).
  11. This is not so fast. "Asin(x)" is faster a few times.
  12. ***********************************************************************/
  13. #ifndef SN_H
  14. #include "sn.h"
  15. #endif
  16. static const char* const func = "AsinBSNW";
  17. //static const SDouble ONE(1.0);
  18. SDouble AsinBSNW(const SDouble& a) {
  19. int d1 = DDCompare(a, ONE);
  20. if( d1 > 0 ) a.SetError(a.DOMAIN_ERR, func, 3150); // |x| > 1
  21. if(a == 0.0) return 0.0; // x = 0
  22. if(d1 == 0) return a.Sign(3105) > 0 ? MPi2() : -MPi2(); // |x| = 1 return pi/2 or -pi/2
  23. // see "sdfrsqrt.cpp"
  24. RealSize C;
  25. uint max_sz = a.MaxSize();
  26. int itrmax = howpow2( (DFIGURES*max_sz)/DOUBLE_FIG+1 ) + 6;
  27. int count = 0;
  28. uint ef = (DOUBLE_FIG*2u)/DFIGURES, fig = C.EffFigures();
  29. bool fullPrec = false; //calclation is done in full precision or not
  30. if(ef > fig) ef = fig;
  31. ef = ceilpow2(ef); // ef = 2^n
  32. SDouble A( Dabs(a) ); // A = |a|
  33. double AD = doubleD(A);
  34. SDouble x, y, delta, sinVal, cosVal;
  35. x = asin(AD);
  36. do {
  37. if((ef = C.SetEffFig(ef)) >= fig) fullPrec = true;
  38. CosSinBS(x, cosVal, sinVal);
  39. y=A-sinVal;
  40. delta = y/cosVal;
  41. x += delta;
  42. ef *= 2;
  43. if(ef >= fig) ef = fig;
  44. C.SetEffFig(0);
  45. count++;
  46. } while( ( !delta.IsMLT(ONE) && (count < itrmax) ) || !fullPrec);
  47. if(count >= itrmax) x.SetError(x.FATAL, func, 34010);
  48. x.iterationCount = count;
  49. return a.Sign() > 0 ? x : -x;
  50. }

sdfasinb.cpp : last modifiled at 2016/08/25 16:35:21(1,832 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).